
***************** figure 2 - top half
clear
set scheme plottig
use "data/both.dta", clear

*prep data
 gen five= (roll1==5)
 gen six = (roll1==0)
 gen one = (roll1==1)
 gen two = (roll1==2)
 gen three = (roll1==3)
 gen four = (roll1==4)
 
label variable five "5"
label variable four "4"
label variable three "3"
label variable two "2"
label variable one "1"
label variable six "0"

 gen five2= (roll2==5)
 gen six2 = (roll2==0)
 gen one2 = (roll2==1)
 gen two2 = (roll2==2)
 gen three2 = (roll2==3)
 gen four2 = (roll2==4)
 
 collapse (mean) roll1 roll2 five six one two three four  five2 six2 one2 two2 three2 four2 ///
 (sem) semq1= roll1 semq2= roll2   semfive=five semsix=six semone=one semtwo=two semthree=three semfour=four ///
 semfive2=five2 semsix2=six2 semone2=one2 semtwo2=two2 semthree2=three2 semfour2=four2 ///
 , by(treat)

gen hiy=roll1+semq1
gen lowy=roll1-semq1

graph twoway (bar roll1  treat if treat<20, recast(scatter) col(plr1) fxsize(100) ///
fi(50) ylabel(0(1)4) legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" )  ///
ylabel(0 1 2  3 4,  labcol(black)) ///
 yline(2.5, lcol(ply1) ) yline(3.47, lcol(plb1) lpat(solid)) ) ///
(rcap hiy lowy treat if treat<20 ,lc(black) ) 	, title("Mean") xtitle("") ytitle("")  ///
nodraw name(mean, replace) scheme(plotplainblind)

gen fiveh=five+semfive
gen fivel=five-semfive
twoway (bar five treat if treat<20 , col(plr1)  recast(scatter) fxsize(100) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap fiveh fivel treat if treat<20 ,lc(black) title("5")   ///
 yline(.16666667, lcol(ply1) ) yline(.3055556, lcol(plb1) lpat(solid))  ///
 ylabel(0(0.1)0.4, grid gmin gmax) ///
 name(five, replace) nodraw)
 
gen fourh=four+semfour
gen fourl=four-semfour
twoway (bar four treat if treat<20 , col(plr1)   recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("") ) ///
(rcap fourh fourl treat if treat<20 ,lc(black) title("4") ///
yline(.16666667, lcol(ply1) ) yline(.25, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmin gmax) ///
nodraw name(four, replace)) 


gen threeh=three+semthree
gen threel=three-semthree
twoway (bar three treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap threeh threel treat if treat<20 ,lc(black) title("3")  ///
yline(.16666667, lcol(ply1) ) yline(.19444444, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax gmin) ///
 nodraw name(three, replace))  

gen twoh=two+semtwo
gen twol=two-semtwo
twoway (bar two treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap twoh twol treat if treat<20 ,lc(black) title("2")  ///
yline(.16666667, lcol(ply1) ) yline(.13888889, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
 nodraw name(two, replace))  

gen oneh=one+semone
gen onel=one-semone
twoway (bar one treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap oneh onel treat if treat<20, lc(black) title("1")  ///
yline(.16666667, lcol(ply1) ) yline(.08333333, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
  nodraw name(one, replace))  

 
  
gen sixh=six+semsix
gen  sixl=six-semsix
twoway (bar six treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap sixh sixl treat if treat<20, lc(black) title("0")  /// 
 yline(.16666667, lcol(ply1) ) yline(.02777778, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
	nodraw name(six, replace))  
  
gr combine mean five four three two one six, row(1) xsize(6.5)  scale(2.5) ysize(3) ///
 imargin(none)  name(e1r1, replace) title("1st Roll, Incentivised", size( vsmall  )  )
graph export "output/figure2a.pdf", as(pdf) replace

***************** figure 2 - bottom half
clear
use "data/both.dta", clear

*prep data
 gen five= (roll2==5)
 gen six = (roll2==0)
 gen one = (roll2==1)
 gen two = (roll2==2)
 gen three = (roll2==3)
 gen four = (roll2==4)
 
label variable five "5"
label variable four "4"
label variable three "3"
label variable two "2"
label variable one "1"
label variable six "0"


 gen five2= (roll2==5)
 gen six2 = (roll2==0)
 gen one2 = (roll2==1)
 gen two2 = (roll2==2)
 gen three2 = (roll2==3)
 gen four2 = (roll2==4)
 
 collapse (mean) roll1 roll2 five six one two three four  five2 six2 one2 two2 three2 four2 ///
 (sem) semq1= roll1 semq2= roll2   semfive=five semsix=six semone=one semtwo=two semthree=three semfour=four ///
 semfive2=five2 semsix2=six2 semone2=one2 semtwo2=two2 semthree2=three2 semfour2=four2 ///
 , by(treat)

gen hiy=roll2+semq2
gen lowy=roll2-semq2

graph twoway (bar roll2  treat if treat<20, recast(scatter) col(plr1) fxsize(100) ///
fi(50) ylabel(0(1)4) legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" )  ///
ylabel(0 1 2  3 4,  labcol(black)) ///
 yline(2.5, lcol(ply1) ) yline(1.53, lcol(plb1) lpat(solid)) )  ///
(rcap hiy lowy treat if treat<20 ,lc(black) ) 	, title("Mean") xtitle("")  ///
nodraw name(mean, replace) scheme(plotplainblind)

gen fiveh=five+semfive
gen fivel=five-semfive
twoway (bar five treat if treat<20 , col(plr1)  recast(scatter) fxsize(100) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap fiveh fivel treat if treat<20 ,lc(black) title("5")   ///
 yline(.16666667, lcol(ply1) ) yline(.02777778, lcol(plb1) lpat(solid))  ///
 ylabel(0(0.1)0.4, grid gmin gmax) ///
 name(five, replace) nodraw)
 
gen fourh=four+semfour
gen fourl=four-semfour
twoway (bar four treat if treat<20 , col(plr1)   recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("") ) ///
(rcap fourh fourl treat if treat<20 ,lc(black) title("4")  ///
yline(.16666667, lcol(ply1) ) yline(.08333333, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmin gmax) ///
nodraw name(four, replace)) 


gen threeh=three+semthree
gen threel=three-semthree
twoway (bar three treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap threeh threel treat if treat<20 ,lc(black) title("3")  ///
yline(.16666667, lcol(ply1) ) yline(.13888889, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax gmin) ///
 nodraw name(three, replace))  

gen twoh=two+semtwo
gen twol=two-semtwo
twoway (bar two treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap twoh twol treat if treat<20 ,lc(black) title("2")  ///
yline(.16666667, lcol(ply1) ) yline(.19444444, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
 nodraw name(two, replace))  

gen oneh=one+semone
gen onel=one-semone
twoway (bar one treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap oneh onel treat if treat<20, lc(black) title("1")  ///
yline(.16666667, lcol(ply1) ) yline(.25, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
  nodraw name(one, replace))  

 
  
gen sixh=six+semsix
gen  sixl=six-semsix
twoway (bar six treat if treat<20 , col(plr1)  recast(scatter) fxsize(80) ///
 fi() legend(off) xlabel(11 "A" 12 "B" 13 "C" 14 "D" ) xtitle("")) ///
(rcap sixh sixl treat if treat<20, lc(black) title("0")  /// 
 yline(.16666667, lcol(ply1) ) yline(.3055556, lcol(plb1) lpat(solid))  ///
 ylabel(none) ytick(0(.1).4, grid gmax) ///
	nodraw name(six, replace))  
  
gr combine mean five four three two one six, row(1) xsize(6.5) ysize(3) scale(2.5) ///
 imargin(none) title("2nd Roll, Unincentivised"  , size( vsmall  )  )
graph export "output/figure2b.pdf", as(pdf) replace


